﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

using PortalIntranet.DatabaseComponents.Administracao;
using PortalIntranet.DatabaseComponents.Comun;
using PortalIntranet.DatabaseComponents.Seguranca;

namespace PortalIntranet.DatabaseComponents.WebParts.Bibliotecas
{
	[Serializable]
	[Table("GaleriasItens")]
	public class BibliotecaItem : Entidade, IAuditoria
	{
		public BibliotecaItem()
		{
			this.SubItens = new HashSet<BibliotecaItem>();
		}

		[Required, MaxLength(100)]
		public string Nome { get; set; }

		[Required, MaxLength(300)]
		public string Descricao { get; set; }

		[Required, MaxLength(300)]
		public string Url { get; set; }

		public int Ordem { get; set; }

		public TipoBiblioteca TipoBiblioteca { get; set; }

		public TipoArquivo TipoArquivo { get; set; }

		#region Biblioteca
		public int BibliotecaId { get; set; }

		public virtual Biblioteca Biblioteca { get; set; }
		#endregion

		#region ItemPai
		public int ItemPaiId { get; set; }

		public virtual BibliotecaItem ItemPai { get; set; }
		#endregion

		#region Auditoria

		#region UsuarioCriacao
		public int? UsuarioCriacaoId { get; set; }

		public virtual Usuario UsuarioCriacao { get; set; }

		public DateTime? DataCriacao { get; set; }
		#endregion

		#region UsuarioModificacao
		public int? UsuarioModificacaoId { get; set; }

		public virtual Usuario UsuarioModificacao { get; set; }

		public DateTime? DataModificacao { get; set; }
		#endregion

		#region UsuarioExclusao
		public int? UsuarioExclusaoId { get; set; }

		public virtual Usuario UsuarioExclusao { get; set; }

		public DateTime? DataExclusao { get; set; }
		#endregion

		#endregion

		#region Navegação
		public virtual ICollection<BibliotecaItem> SubItens { get; set; }
		#endregion
	}

	internal class BibliotecaItemConfiguration : EntityTypeConfiguration<BibliotecaItem>
	{
		internal BibliotecaItemConfiguration()
		{
			this.HasRequired(b => b.Biblioteca)
				.WithMany(i => i.Itens)
				.HasForeignKey(b => b.BibliotecaId);

			this.HasOptional(i => i.ItemPai)
				.WithMany(u => u.SubItens)
				.HasForeignKey(i => i.ItemPaiId);
		}
	}
}
